package com.deep.ware.controller.web;

import com.deep.ware.model.entity.WareSkuEntity;
import com.rabbitmq.client.Channel;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;

/**
 * @author Deep
 * @date 2022/2/18
 */
@RequestMapping("ware")
@RestController
public class TestController {
    @Autowired
    private RabbitTemplate rabbitTemplate;

    @GetMapping("/testMQ")
    public String testMQ() {
        WareSkuEntity wareSkuEntity = new WareSkuEntity();
        wareSkuEntity.setSkuName("华为");
        rabbitTemplate.convertAndSend("stock-event-exchange", "stock.locked", wareSkuEntity);
        return "ok";
    }

//    @RabbitListener(queues = "stock.release.stock.queue")
//    public void listener(WareSkuEntity wareSkuEntity, Channel channel, Message message) throws IOException {
//        System.out.println("收到过期的订单消息:" + wareSkuEntity.getSkuName());
//        channel.basicAck(message.getMessageProperties().getDeliveryTag(), false);
//    }
}
